<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <right-toolbar  @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table :data="TNavigationInfoList" >
      <el-table-column label="金刚导航栏logo" align="center" prop="logo" >
      <template   slot-scope="scope">
        <el-popover placement="left" trigger="click" width="400">
          <img :src="scope.row.logo" width="100%" />
          <img
            slot="reference"
            :src="scope.row.logo"
            :alt="scope.row.logo"
            style="max-height: 70px;max-width: 70px; padding:                     5px"
          />
        </el-popover>
      </template>
      </el-table-column>
      <el-table-column label="金刚导航栏名称" align="center" prop="navigationName" />
      <el-table-column label="金刚导航栏url地址路径" align="center" prop="navigationUrl" />
      <el-table-column label="排序" align="center" prop="sort" />
      <el-table-column label="链接类型" align="center" prop="linkType" />
<!--      <el-table-column label="导航栏状态" align="center" prop="isValid" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['pos:TNavigationInfo:edit']"
          >修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 添加或修改金刚导航栏对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="主键id" prop="id" hidden>
          <el-input v-model="form.id" placeholder="请输入主键id" />
        </el-form-item>
        <el-form-item label="金刚导航栏logo">
          <imageUpload v-model="form.logo"/>
        </el-form-item>
        <el-form-item label="金刚导航栏名称" prop="navigationName">
          <el-input v-model="form.navigationName" placeholder="请输入金刚导航栏名称" />
        </el-form-item>
        <el-form-item label="金刚导航栏url地址路径"  prop="navigationUrl">
          <el-input v-model="form.navigationUrl" placeholder="跳转路径" :disabled="form.id == 'e7f5a732646e4c66a257753692749e9d' ? false : true" />
        </el-form-item>
        <el-form-item label="排序" prop="sort">
          <el-input v-model="form.sort" placeholder="请输入排序" />
        </el-form-item >
        <el-form-item label="链接类型" prop="sort">
          <el-radio-group v-model="form.linkType">
            <el-radio label="0">内链</el-radio>
            <el-radio label="1">外链</el-radio>
          </el-radio-group>
        </el-form-item >
        <el-form-item label="导航栏" prop="isValid" v-if="false">
          <el-input v-model="form.isValid" placeholder="请输入导航栏"  />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTNavigationInfo, getTNavigationInfo, delTNavigationInfo, addTNavigationInfo, updateTNavigationInfo, exportTNavigationInfo } from "@/api/pos/TNavigationInfo";

export default {
  name: "TNavigationInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 总条数
      total: 0,
      // 金刚导航栏表格数据
      TNavigationInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        logo: null,
        navigationName: null,
        navigationUrl: null,
        sort: null,
        isValid: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          // { required: true, message: "主键id不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询金刚导航栏列表 */
    getList() {
      this.loading = true;
      listTNavigationInfo().then(response => {
        this.TNavigationInfoList = response.rows;
        // this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        logo: null,
        navigationName: null,
        navigationUrl: null,
        sort: null,
        isValid: 0,
        createTime: null
      };
      this.resetForm("form");
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加金刚导航栏";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTNavigationInfo(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改金刚导航栏";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTNavigationInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
  }
};
</script>
